package tests;

import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;

import data.Data;
import data.GeneralDefinitions.ClusteringPriorityParameters;
import data.GeneralDefinitions.OrderingParameters;
import data.LUN;
import data.LUNPerTimeUnit;
import data.TimeUnit;

public class ClusteringData implements Data {

	HashMap<Integer, double[]> lunVectors;
	int[] luns;

	private static final int numClusters = 10;
	private static final int numVectorsInCluster = 7;
	private static final int vectorSize = 50;


	public ClusteringData() {

		//this stub created 50 vectors of size 50.
		//the vectors are created by the following method:
		//	1. 	10 vectors of size 50 are created randomly from 10,-10 values
		//	2.	for each of the original vectors, we perturb the vector by adding 1 or -1 to each of its values, randomly
		//	3.	we add the vectors to the hashMap that describes the LUN
		//each of the perturbed vectors should be in the same cluster as its parent.
		lunVectors = new HashMap<Integer, double[]>();
		luns = new int[numClusters*numVectorsInCluster];

		double[] zeroVector = new double[vectorSize];	//base vector for the original vectors
		Arrays.fill(zeroVector, 0);

		for (int i=0; i<numClusters; i++){
			double[] vec = createVector(i*numVectorsInCluster, zeroVector, 98);
			for (int j=1; j<numVectorsInCluster; j++){
				createVector(i*numVectorsInCluster+j, vec, 1);
			}
		}
	}


	//creates a perturbed vector from an original vector, using the given offset
	private double[] createVector(int lunIndex, double[] baseVector, int offset){
		luns[lunIndex] = lunIndex;
		double[] vec = new double[vectorSize];
		for (int k=0; k<vectorSize; k++){
			double b = Math.random();
			vec[k] = baseVector[k] + (b<0.5 ? +offset : -offset);
		}
		lunVectors.put(lunIndex, vec);
		//System.out.println(lunIndex + " = " + Arrays.toString(vec));
		return vec;
	}

	@Override
	public LUN getLUN(int LUNid) {
		return null;
	}

	@Override
	public LUNPerTimeUnit getLUNPerTimeUnit(int TimeUnitID, int LUNid) {
		return null;
	}

	@Override
	public double[] getLUNVector(int LUNid, ClusteringPriorityParameters clusterType, Calendar startDate, Calendar endDate) {
		return lunVectors.get(LUNid);
	}

	@Override
	public int[] getOrderedLUNVector(OrderingParameters orderingParameter) {
		return null;
	}

	@Override
	public TimeUnit getTimeUnit(int TimeUnitID) {
		return null;
	}

	@Override
	public long getTotalBytesWritten(int TimeUnitID) {
		return 0;
	}

	@Override
	public double getTotalSize() {
		return 0;
	}

	@Override
	public int[] getUnactiveLUNs(int threshold) {
		return null;
	}

	@Override
	public void parse(String filename) {
	}


	@Override
	public int[] getLUNs() {
		return luns;
	}

	@Override
	public int getNumOfTimeUnits() {
		return 5;
	}


	@Override
	public void addLun(int lun_id, int size) {
	}

	@Override
	public void addLunPerTimeUnit(int lun_id, int timeunit_id,
			double kbWritten, double kbRead, double numOfReads,
			double numOfWrites) {
	}

	@Override
	public void addTimeUnit(int timeUnit_id, int size) {
	}


	@Override
	public void endTransactions() {
	}


	@Override
	public LUNPerTimeUnit[] getAllLunPerTimeUnits(int timeUnitId, int start,
			int end, OrderingParameters orderingParameter) {
		return null;
	}


	@Override
	public String getFIleName() {
		return null;
	}


	@Override
	public void addTimeUnit(int timeUnit_id, int size, Calendar d) {
		// TODO Auto-generated method stub
		
	}

}
